﻿using DevExpress.Drawing;
using DevExpress.ExpressApp.DC;
using DevExpress.ExpressApp.Editors;
using DevExpress.Persistent.Base;
using DevExpress.Persistent.BaseImpl;
using DevExpress.Persistent.Validation;
using DevExpress.Xpo;
using EasyXaf.EntityDesigner.BusinessObjects.Entities;
using EasyXaf.EntityDesigner.BusinessObjects.Entities.EntityProperties;
using System.ComponentModel;

namespace EasyXaf.EntityDesigner.BusinessObjects.Entities.Appearances;

/// <summary>
/// 外观
/// </summary>
[XafDisplayName("外观")]
[XafDefaultProperty(nameof(AppearanceId))]
public partial class Appearance : BaseObject
{
	private string _appearanceId;
	private string _appearanceItemType;
	private string _context;
	private string _criteria;
	private string _targetItems;
	private string _backColor;
	private string _fontColor;
	private DXFontStyle? _fontStyle;
	private ViewItemVisibility? _visibility;
	private bool? _enabled;
	private string _method;
	private int? _priority;
	private EntityProperty _targetProperty;
	private Entity _entity;

	/// <summary>
	/// 外观Id
	/// </summary>
	[XafDisplayName("外观Id")]
	[RuleRequiredField]
	public string AppearanceId
	{
		get => _appearanceId;
		set => SetPropertyValue(nameof(AppearanceId), ref _appearanceId, value);
	}

	/// <summary>
	/// 项目类型
	/// </summary>
	[XafDisplayName("项目类型")]
	[VisibleInListView(false)]
	public string AppearanceItemType
	{
		get => _appearanceItemType;
		set => SetPropertyValue(nameof(AppearanceItemType), ref _appearanceItemType, value);
	}

	/// <summary>
	/// 上下文
	/// </summary>
	[XafDisplayName("上下文")]
	[VisibleInListView(false)]
	public string Context
	{
		get => _context;
		set => SetPropertyValue(nameof(Context), ref _context, value);
	}

	/// <summary>
	/// 外观条件
	/// </summary>
	[XafDisplayName("外观条件")]
	[VisibleInListView(true)]
	[Size(SizeAttribute.Unlimited)]
	public string Criteria
	{
		get => _criteria;
		set => SetPropertyValue(nameof(Criteria), ref _criteria, value);
	}

	/// <summary>
	/// 目标项目
	/// </summary>
	[XafDisplayName("目标项目")]
	[VisibleInListView(false)]
	public string TargetItems
	{
		get => _targetItems;
		set => SetPropertyValue(nameof(TargetItems), ref _targetItems, value);
	}

	/// <summary>
	/// 背景颜色
	/// </summary>
	[XafDisplayName("背景颜色")]
	[VisibleInListView(false)]
	public string BackColor
	{
		get => _backColor;
		set => SetPropertyValue(nameof(BackColor), ref _backColor, value);
	}

	/// <summary>
	/// 字体颜色
	/// </summary>
	[XafDisplayName("字体颜色")]
	[VisibleInListView(false)]
	public string FontColor
	{
		get => _fontColor;
		set => SetPropertyValue(nameof(FontColor), ref _fontColor, value);
	}

	/// <summary>
	/// 字体样式
	/// </summary>
	[XafDisplayName("字体样式")]
	[VisibleInListView(false)]
	public DXFontStyle? FontStyle
	{
		get => _fontStyle;
		set => SetPropertyValue(nameof(FontStyle), ref _fontStyle, value);
	}

	/// <summary>
	/// 是否显示
	/// </summary>
	[XafDisplayName("是否显示")]
	[VisibleInListView(false)]
	public ViewItemVisibility? Visibility
	{
		get => _visibility;
		set => SetPropertyValue(nameof(Visibility), ref _visibility, value);
	}

	/// <summary>
	/// 是否启用
	/// </summary>
	[XafDisplayName("是否启用")]
	[VisibleInListView(false)]
	public bool? Enabled
	{
		get => _enabled;
		set => SetPropertyValue(nameof(Enabled), ref _enabled, value);
	}

	/// <summary>
	/// 条件方法
	/// </summary>
	[XafDisplayName("条件方法")]
	[VisibleInListView(false)]
	public string Method
	{
		get => _method;
		set => SetPropertyValue(nameof(Method), ref _method, value);
	}

	/// <summary>
	/// 优先级
	/// </summary>
	[XafDisplayName("优先级")]
	[VisibleInListView(false)]
	public int? Priority
	{
		get => _priority;
		set => SetPropertyValue(nameof(Priority), ref _priority, value);
	}

	/// <summary>
	/// 目标属性
	/// </summary>
	[XafDisplayName("目标属性")]
	[DataSourceProperty(nameof(TargetPropertyDataSource))]
	[Association("TargetProperty-Appearances")]
	public EntityProperty TargetProperty
	{
		get => _targetProperty;
		set => SetPropertyValue(nameof(TargetProperty), ref _targetProperty, value);
	}

	/// <summary>
	/// 实体
	/// </summary>
	[XafDisplayName("实体")]
	[Browsable(false)]
	[Association("Entity-Appearances")]
	public Entity Entity
	{
		get => _entity;
		set => SetPropertyValue(nameof(Entity), ref _entity, value);
	}

	[Browsable(false)]
	public IList<EntityProperty> TargetPropertyDataSource
	{
		get => GetTargetPropertyDataSource();
	}

	public Appearance(Session session)
		: base(session)
	{
	}

	private partial IList<EntityProperty> GetTargetPropertyDataSource();
}
